<?php

namespace App\Http\Controllers\V1;

use App\Http\Controllers\ApiBaseController;
use App\Models\Areas;
use Illuminate\Http\Request;

class AreasController extends ApiBaseController
{

    public function getList(Request $request){
        $items = Areas::filter($request->all())->select('id', 'parent_id', 'level_type', 'name', 'short_name')->get();
        return success(['data' => $items],'添加成功');
    }
    public function getHookAreas(){
        $province = \App\Models\Areas::where('level_type',1)->selectRaw('0 as parent_id')->addSelect('id','level_type','short_name')->get();
        $city = \App\Models\Areas::where('level_type',2)->select('id','parent_id','level_type','short_name')->get();
        $datas = array_merge($province->toArray(),$city->toArray());
        $items = makeTree($datas);
        return success(['data' => $items],'添加成功');
    }
}
